package com.gh.Service;


import javafx.util.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;
import org.springframework.mail.SimpleMailMessage;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;
import java.util.List;
import java.util.Map;

@Service
public class MailService  implements EmailService{
    @Value("${spring.mail.username}")
    private String from;

    @Autowired
    private JavaMailSender mailSender;



    public void sendSimpleMail(String to,String subject,String content){
        SimpleMailMessage message =new SimpleMailMessage();
            message.setTo(to); //接收者
            message.setSubject(subject);
            message.setText(content);
            message.setFrom(from); //发送者

        mailSender.send(message);

    }


    public void sendHtmlMail(String to,String subject,String content) throws MessagingException {

        MimeMessage message =mailSender.createMimeMessage();
        MimeMessageHelper helper =new MimeMessageHelper(message,true);
            helper.setTo(to); //接收者
            helper.setSubject(subject);
            helper.setText(content);
            helper.setFrom(from); //发送者
        mailSender.send(message);
    }



    
    @Override
    public void sendAttachmentsMail(String sendTo, String titel, String content, List<Pair<String, File>> attachments) {

    }

    @Override
    public void sendTemplateMail(String sendTo, String titel, Map<String, Object> content, List<Pair<String, File>> attachments) {

    }


}
